﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASPPatterns.Chap3.Layered.Service;

namespace ASPPatterns.Chap3.Layered.Presentation
{
    public class ProductListPresentation
    {
        private IProductListView _productListView;
        private Service.ProductService _productService;

        public ProductListPresentation(IProductListView productListView, Service.ProductService productService)
        {
            _productListView = productListView;
            _productService = productService;
        }

        public void Display()
        {
            ProductListRequest productListRequest = new ProductListRequest();
            productListRequest.CostomerType = this._productListView.CustomerType;

            ProductListResponse productListResponse = this._productService.GetAllProductsFor(productListRequest);
            if (productListResponse.Success)
            {
                _productListView.Display(productListResponse.Products);
            }
            else
            {
                _productListView.ErrorMessage = productListResponse.Message;
            }
        }
    }
}
